package com.aspyn.tetris;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.view.View;

public class DrawView extends View {

	private int screenWidth;
	private int screenHeight;

	private GridManager gridManager;
	
	public DrawView(Context context, int sW, int sH, GridManager gM) {

		//Set up view
		super(context);
		setFocusable(true);
		setFocusableInTouchMode(true);

		//set up dimension variables and Grid Manager
		screenWidth = sW;
		screenHeight = sH;
		gridManager = gM;

		Shape shape = new Shape();
		Point p = new Point(2,2);
		shape.create(ShapeType.T, p, gM);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onDraw(Canvas c) { 
		int gridWidth = gridManager.getGridWidth(), gridHeight = gridManager.getGridHeight();

		for (int row = 0; row<gridHeight; row++) {
			for (int column = 0; column<gridWidth; column++) {
				if (gridManager.getGridPosOccupied(row, column) != ShapeType.NONE) {
					//Color grid square based off which shape (colors differentiate between the shapes), FOR NOW ALL RED
					ShapeType shape = gridManager.getGridPosOccupied(row, column);

					Paint paint = new Paint();

					//1 is square, 2 is LLeft, 3 is LRight, 4 is S, 5 is Z, 6 is T, 7 is Stick
					Shape s = new Shape();
					paint.setColor(s.getColor(shape));
					/*if (shape == 1) {
						paint.setColor(s.getColorForShapeType(ShapeType.SQUARE));
					}
					else if (shape == 2) {
						paint.setColor(s.getColorForShapeType(ShapeType.LLEFT));
					}
					else if (shape == 3) {
						paint.setColor(s.getColorForShapeType(ShapeType.LRIGHT));
					}
					else if (shape == 4) {
						paint.setColor(s.getColorForShapeType(ShapeType.S));
					}
					else if (shape == 5) {
						paint.setColor(s.getColorForShapeType(ShapeType.Z));
					}
					else if (shape == 6) {
						paint.setColor(s.getColorForShapeType(ShapeType.T));
					}
					else if (shape == 7) {
						paint.setColor(s.getColorForShapeType(ShapeType.STICK));
					}*/
					paint.setAntiAlias(true);

					RectF rect = new RectF(gridManager.grid[row][column].x-gridManager.getBoxWidth()/2,gridManager.grid[row][column].y-gridManager.getBoxHeight()/2,
							gridManager.grid[row][column].x+gridManager.getBoxWidth()/2,gridManager.grid[row][column].y+gridManager.getBoxHeight()/2);
					c.drawRect(rect, paint);
				}
			}
		}
		invalidate();
	}
}
